package self.hoy.demo.rabbitmq.ps;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import self.hoy.demo.rabbitmq.Constant;
import self.hoy.demo.rabbitmq.util.ConnectionUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 发布订阅模式
 * @author hyh
 * @date 2020/6/7
 */
public class Send implements Constant {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明交换机
        channel.exchangeDeclare(FANOUT_EXCHANGE_NAME, "fanout");//fanout 意为扇出，这里表示：不处理路由键
        String msg = "Hello World! publish subscribe";
        channel.basicPublish(FANOUT_EXCHANGE_NAME, "", null, msg.getBytes());
        System.out.println("send msg : " + msg);


        channel.close();
        connection.close();
    }
}
